#!/usr/bin/env bash

server=""
port=""
init=0

while getopts "s:p:i" opt; do
  case $opt in
    s)
      server=$OPTARG
      ;;
    p)
      port=$OPTARG
      ;;
    i)
      init=1
      ;;
    \?)
      echo "Invalid option: -$OPTARG"
      exit 1;
      ;;
  esac
done

export KONG_DATABASE_PORT=tcp://$server:$port
export KONG_PG_HOST=$server

if [ $init -eq 1 ]
  kong migrations bootstrap
  exit 1
fi


kong start

echo "kong start completed"